/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package contest.controller;

import contest.util.ErrorLog;
import contest.util.ResPathConstant;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Admin
 */
public abstract class WebPage extends WebInit implements IWebAction {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            response.setContentType("text/html;charset=UTF-8");
            if (request.getParameter("AJAX") != null && request.getParameter("AJAX").equals("true")) {
                this.handleAjax(request, response);
            } else {
                this.loadRequest(request);
                this.handleGet(request, response);
            }
            //REMOVE HISTORY DATA IS STORED FROM 'PREVIOUS_DATA' SESSION
            this.sessionProcess.remove("PREVIOUS_DATA");
        }catch (Exception ex) {
            ErrorLog.catchException(ResPathConstant.ERROR_LOG_TXT,(Exception)ex);
            forward("/error?code="+getServletContext().getInitParameter("code-error-page"), request, response);
        } 
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            if (request.getParameter("AJAX") != null && request.getParameter("AJAX").equals("true")) {
                this.handleAjax(request, response);
            } else {
                this.loadRequest(request);
                this.handleGet(request, response);
            }
        }catch (Exception ex) {
             ErrorLog.catchException(ResPathConstant.ERROR_LOG_TXT,(Exception)ex);
             forward("/error?code="+getServletContext().getInitParameter("code-error-page"), request, response);
        }
    }
    
}
